#ifndef QMYSQL_H
#define QMYSQL_H

#include <QObject>
#include <QDebug>

#include "qdatasession.h"

// mysql 数据库连接
class QMysql :public QLimitSession
{
public:
    explicit QMysql(QString host,int port,QString user,QString password,QString dbName):QLimitSession(){
        auto connectionName = QSqlDatabase::defaultConnection;
        if(!QSqlDatabase::contains(connectionName)){
            this->connection = QSqlDatabase::addDatabase("QMYSQL",connectionName);
        }else{
            this->connection = QSqlDatabase::database(connectionName);
        }
        this->connection.setHostName(host);
        this->connection.setUserName(user);
        this->connection.setPassword(password);
        this->connection.setPort(port);
        this->connection.setDatabaseName(dbName);
        this->connection.setConnectOptions("MYSQL_OPT_RECONNECT=1");
    }
};

#endif // QMYSQL_H
